Transfer modes can be specified by type, also called component mode. Transfer mode types in QuickDraw GX are called component modes because QuickDraw GX allows each color component to have its own transfer mode type. In RGB color space, for example, the red component of the color may be drawn with a different transfer mode type than the blue component.
QuickDraw GX supports several conceptual categories of component modes:
The characteristics of and most typical uses for the component modes within each category are summarized in the following subsections.
Note
Even though QuickDraw GX supports 18 different component modes, most applications in most situations need only one, an arithmetic mode called
copy mode.
In copy mode, the source color completely replaces the destination color. Copy mode is the default transfer mode in QuickDraw GX; therefore, you need information about other transfer modes only if you want them for special effects.
In arithmetic transfer modes, the numerical values of source and destination for a color component are combined arithmetically to determine the result value for that color component. In most color spaces, a color component value can vary from 0 (no intensity) to 0xFFFF (maximum intensity). You can also use the constant gxColorValue1 to represent maximum intensity (0xFFFF).
Figure 39 shows examples of drawing with the arithmetic transfer modes. In each case, the source image (left) combines with the destination image (center) to produce the result image (right). You can think of the images either as two bitmaps, or as two source shapes (cloud and background) that are drawn over two destination shapes (letter and background).
Each example shows how transfer mode affects drawing within a single color component (reflected as shades of gray in the figure, where black equals 0 and white equals 0xFFFF). The constant that specifies the transfer mode type is shown to the right of each example. Note also that two of the arithmetic transfer modes use an operand, a numerical value that affects the outcome of the transfer-mode operation.
Figure 39 Arithmetic transfer modes
The constants that define transfer mode type are defined in the gxComponentModes enumeration. The arithmetic modes have the following values and meanings:
No mode. No transfer occurs. For this component of the color, the destination is left as it was. This mode is useful for suppressing drawing when certain logical conditions are met, or for not drawing one color component while allowing other components to be drawn. |
||
Copy mode. The source color component is copied to the destination. The destination component is ignored. This is the most common transfer mode, and is the default for QuickDraw GX. |
||
Add mode. The source color component is added to the destination component, but the result is not allowed to exceed the maximum value ( 0xFFFF or gxColorValue1 ; white in Figure 39 ). |
||
Blend mode. The result is the average of the source |
||
Migrate mode. The destination color component is moved toward the source component by the value of the step specified in the operand component (0.25, or 0x4000 in Figure 39 ). Migrate mode is similar to blend mode, except that the change in destination component is an absolute amount, rather than a proportion of the difference between it and the source component. If the source has a greater color component value than the destination, the migration is positive; if the destination has a greater value than the source, the migration is negative. In either case, the amount of migration cannot be greater than the difference between the destination and the source values. |
||
Minimum mode. The source component replaces the destination component only if the source component has a smaller value. (In Figure 39 , drawing occurs only within the area occupied by the cloud.) |
||
Maximum mode. The source component replaces the destination component only if the source component has a larger value. (In Figure 39 , drawing occurs only outside of the area occupied by the cloud.) |
The operand parameter is used by blend mode to specify the ratio of source and destination component. It is used by migrate mode to specify the step size by which the destination component moves toward the source component. Figure 40 shows examples of the result of drawing with blend mode, using several different values for the operand.
Figure 40 Blend example with different operand values
The highlight transfer mode is used for highlighting in color applications. It is most commonly used to draw (and clear) a colored rectangle around a selection, without altering the color of the item or items selected. In text, it gives the effect of drawing over the letters with a highlighting pen.
Like some of the arithmetic transfer modes, highlight mode uses an operand to control the outcome of the highlighting operation. Highlight mode operates by replacing the source color with the operand color, and the operand color with the source color, in the destination.
The upper row of images in Figure 41 shows a simple example of the application of highlight mode. The operand value is represented with shading rather than as a number, to illustrate how its color affects colors in the image. The source shape is a white rectangle that is drawn over the two middle letters in the destination image. (The gray letters in the line of text in the destination image represent the same color-component value as the operand, and the white area around the letters in the destination represents the same color-component value as the source.)
Figure 41 Highlight transfer mode
Note that black in the destination is unaffected, whereas white becomes gray and gray becomes white. A single constant specifies highlight mode, with the following value and meaning:
Highlight mode. The source component and operand component are swapped in the destination. Other components in the destination are ignored. |
In highlight mode, the source color can be thought of as the "background" color that is to be highlighted, and the operand color is the color of the highlighting pen. As the lower set of images in Figure 41 shows, redrawing a highlighted selection causes the source and operand colors to swap once more, effectively removing the highlighting.
The operand for highlight mode is a normal color component value that varies from 0 (no intensity) to the maximum intensity permitted for that component (normally 0xFFFF , or gxColorValue1 ).
QuickDraw GX applies highlight mode only if all components in the color space specify it. An error occurs if some components specify highlight mode and others do not.
In Boolean transfer modes, the result value for a color component is determined by bit operations performed on the source and destination component values. Boolean transfer modes are most common in black-and-white drawing; in any bit depth other than 1, they yield results that can be difficult to predict because they depend on the states of the individual bits in each color-component value.
Figure 42 shows examples of drawing with the Boolean transfer modes at a bit depth of 1. In each case, the source image combines with the destination image to produce the result image. In these examples, black represents a bit value of 0 (clear), and white represents a bit value of 1 (set). The constant that specifies the transfer mode type is shown to the right of each example.
Figure 42 Boolean transfer modes (1-bit depth)
The Boolean modes have the following values and meanings:
Even though they are most easily explained in terms of single-bit depths, Boolean modes are not restricted to 1-bit drawing. They can be used with any kind of color values.
In pseudo-Boolean transfer modes, the result value for a color component is determined by normalizing the source and destination values and performing a simple arithmetic operation, to achieve consistent and predictable results analogous to 1-bit Boolean operations.
Figure 43 shows examples of drawing with the pseudo-Boolean transfer modes. In each case, the source image combines with the destination image to produce the result image. The constant that specifies the transfer mode type is shown to the right of each example.
Figure 43 Pseudo-Boolean transfer modes
The constants for the pseudo-Boolean component modes have the following values and meanings:
Note that the pseudo-Boolean and Boolean modes are similar in several ways:
The difference between the pseudo-Boolean and Boolean modes is that, for multi-bit pixel depths, the results for gxRampAndMode , gxRampOrMode , and gxRampXorMode are predictable and vary smoothly and continuously with component intensity. For 1-bit depths, these modes are identical to their Boolean equivalents.
The pseudo-Boolean modes are commonly used as component modes for alpha channels in color spaces that have an alpha channel. For more information, see "Alpha-Channel Transfer Modes" .
Several QuickDraw GX color spaces ( gxRGBASpace , gxARGB32Space and gxGrayASpace ) have an alpha channel. This is an additional color component that controls the opacity or transparency of a color. For example, a red pixel in a source image can be completely opaque, in which case it typically retains its red color when drawn over a blue pixel in the destination image. Or, the pixel can be completely transparent, in which case it typically loses all its color and turns totally blue when drawn over a blue pixel. Or, it can have an opacity of, say, 0x7FFF (50%), in which case it typically turns magenta when drawn over a blue pixel.
Alpha channel values can be used to allow parts of one image to show through "holes" in another, to show translucency in objects that are drawn over other objects, and to perform anti-aliasing (smoothing of jagged edges) by giving feathered, semi-transparent borders to opaque objects.
When assigning transfer modes to colors with an alpha channel, you typically use two different kinds of modes:
This section describes how the different modes within each category work to give you the results you want.
Figure 44 shows examples of how values for a color component might be calculated, given a source image and a destination image consisting of objects (or pixels) that differ in opacity. In each example, the source image (an opaque, light gray cloud against a transparent black background) combines with the destination image (an opaque, dark gray "A" on a transparent black background), to form the result image. The constant that specifies the transfer mode type is shown to the right of each example.
Each example shows how the alpha-channel transfer mode affects drawing within a single color component. The mode takes into account not only the source and destination color components, but the source and destination opacities as well.
Figure 44 Alpha-channel transfer modes
The constants for the alpha-channel component modes have the following values and meanings:
As Figure 44 shows, the gxOverMode mode is similar to the arithmetic transfer mode gxCopyMode , except that it allows for transparency in the source image. Likewise, the gxAtopMode mode is similar to gxCopyMode , but it preserves the transparency of the destination image by clipping the opaque source to the destination image. The gxExcludeMode mode is somewhat like the Boolean transfer mode gxXorMode , in that opaque parts of each image appear only where the other is not opaque. The gxFadeMode mode is like the arithmetic gxBlendMode , except that the operand that controls the blend ratio is determined by the relative opacities.
Note that the images shown in Figure 44 are very simple and their opacities are either 0 (completely transparent) or gxColorValue1 (completely opaque). Because an alpha component can have a wide range of partial opacities, very sophisticated translucency and color-blending effects are possible, as well as the simple masking effects shown here.
The exact formulas for determining result color are the following. In these formulas, sA = source alpha-channel value; dA = destination alpha-channel value; sC = source color-component value; dC = destination color-component value; and rC = result color-component value.
For calculating the result value for the alpha channel itself, you typically use one of the arithmetic or pseudo-Boolean transfer modes presented in the previous sections--one that takes into account only the source and destination opacities. Figure 45 shows typical modes used and their effects on opacity, using the same images is those presented in Figure 44 . In this figure, black represents complete transparency and white represents complete opacity. (If alpha-channel values between the two extremes existed in these examples, they would be shown in shades of gray.)
Figure 45 Typical modes used to determine result opacity for the alpha channel
Note from Figure 45 that the mode you use to determine the result opacity of the alpha channel usually depends on what alpha-channel mode you use to get color-component values:
Note
When converting a color from a color space that does not have an alpha channel to one that does, QuickDraw GX sets the alpha channel intensity to maximum (opaque). When a color is converted from a color space that does have an alpha channel to one that does not, the alpha channel is lost.
Two common applications for alpha-channel colors involve making objects or images partially opaque to give a translucent effect, and smoothing jagged edges on objects drawn at low resolution.
You can create a bitmap in which the alpha-channel values of the pixels vary smoothly in one or more directions, thus creating a transparency ramp that allows the destination image to show through the source image to varying degrees across the bitmap. Color Plate 2 at the front of this book, for example, shows the kind of effect that can be achieved with a simple alpha-channel ramp.
The smoothing of jagged edges on displayed objects is called anti-aliasing. You can perform anti-aliasing by modifying the alpha-channel values of the pixels surrounding the edges of an opaque object. You make an individual pixel more or less opaque, based on the proportion of that pixel that the object is computed to cover.
In Figure 46 , for example, the left image shows the computed position of the edge of a shape in a bitmap. The center image shows how that edge is displayed normally, given the resolution of the bitmap. The right image shows that edge as it might be displayed with anti-aliasing applied. The apparent jaggedness is decreased because pixels near the edge allow the background to show through to varying degrees.
| Previous | Chapter Contents | Chapter Top | Next |